<?php
/**
 *   OPENSHOP 买家show模块
 * 
 *   @link        http://baison.com.cn
 *   @copyright   Baison, Inc.
 *   @package     OpenShop
 *   @version     $Id: buyer_show.php,v 1.0 2009/08/14 09:35:58 modified $
 *   @author      jiajun <jiajun@baison.com>
 */


define('IN_OS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/cls_json.php');

require_once(ROOT_PATH . 'admin/includes/cls_ftp.php');

$user_id = $_SESSION["user_id"];

if ($_REQUEST['act'] == 'upload_pic')
{

	if (empty($_SESSION['user_id'])){
    	os_header("Location: user.php");
    	exit;		
	}
	
    $goods_id =  intval($_REQUEST['id']); 
    
    $smarty->assign('user_id',      $user_id);
    $smarty->assign('goods_id',      $goods_id);
    
	$smarty->display('buyer_show.dwt');

}

elseif ($_REQUEST['act'] == 'upload')
{
	$goods_id = intval($_POST['goods_id']);
	$img_path = '';
	$upload_time = gmtime();
	
	$ftp = new cls_ftp();
	$ftp->setting('buyer_show', 'buyer_show'); 

	$ip_address = real_ip();

    $ftp->connect();
    $affix_data = $ftp->put_up($_FILES['img_file']);
    
    if ($affix_data !== false)
    {
        $img_path = $affix_data['virtual_path'];
    }
    $ftp->quit();
    
    /*插入数据*/

    $sql = "INSERT INTO ".$os->table('buyer_show')."(goods_id, user_id, ip_address, img_path, upload_time) ".
           "VALUES ('$goods_id', '$user_id', '$ip_address', '$img_path', '$upload_time')";
    $db->query($sql);
    
    $smarty->assign('flag',1);
    $smarty->assign('user_id',      $user_id);
    $smarty->assign('goods_id',      $goods_id);    
    
	$smarty->display('buyer_show.dwt');

}

?>